#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstring>
#include <queue>
using namespace std;
const int N = 120;
char map[N][N];
bool via[N][N];
typedef pair<int, int> pii;
queue<pii> q;
int n, m;
char readchar()
{
	char c;
	while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
	return c;
}
int dy[] = { 1,0,-1,0 };
int dx[] = { 0,1,0,-1 };
void bfs(int starty, int startx)
{
	via[starty][startx] = true;
	q.push({ starty,startx });
	while (!q.empty())
	{
		auto ns = q.front();
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int y = ns.first + dy[i];
			int x = ns.second + dx[i];
			if (y > n || y<1 || x>m || x < 1)continue;
			if (via[y][x])continue;
			if (map[y][x] == '0')continue;
			via[y][x] = true;
			q.push({ y,x });
		}
	}
}
int main()
{
	int cnt = 0;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		for (int j = 1; j <= m; j++)
		{
			map[i][j] = readchar();
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (map[i][j] != '0'&& !via[i][j])
			{
				cnt++;
				bfs(i, j);
			}
		}
	}
	printf("%d", cnt);
	return 0;
}